export default{
	
	//开启命名空间
	namespaced:true,
	
	state:() => ({
		address:JSON.parse(uni.getStorageSync('user')||'{}'),
		token:uni.getStorageSync('token')||'',
		userInfo:JSON.parse(uni.getStorageSync('userinfo')||'{}'),
		//重定向的object(openType info)
		redirectInfo:null
	}),
	
	mutations:{
		//更新token
		updateToken(state,token){
			state.token = token
			this.commit('m_user/saveTokenToStorage')
		},
		
		saveTokenToStorage(state){
			uni.setStorageSync('token',state.token)
		},
		
		
		//更新收货地址
		updateAddress(state,address){
			state.address = address
			this.commit('m_user/saveAddressToStorage')
		},
		
		//持久化address
		saveAddressToStorage(state){
			uni.setStorageSync('user',JSON.stringify(state.address))
		},
		
		//更新用户信息
		updateUserInfo(state, userInfo){
			state.userInfo = userInfo
			this.commit('m_user/saveUserInfoToStorage')
		},
		
		//将用户信息持久化保存
		saveUserInfoToStorage(state){
			uni.setStorageSync('userinfo',JSON.stringify(state.userInfo))
		},
		//更新重定向对象信息
		updateRedirectInfo(state,info){
			state.redirectInfo = info
			console.log(state.redirectInfo)
		}
		
	},
	
	getters:{
		
		addstr(state) {
			if (!state.address.provinceName) return ''
			
			return state.address.provinceName + state.address.cityName + state.address.countyName + state.address.detailInfo
		}
	}
}